#!/bin/bash
export HOMEDIR=$(dirname $(dirname $(readlink -f "${BASH_SOURCE[0]}")))
source $HOMEDIR/scripts/init-env.sh

# 诊断
if [ $ptk_global_track_level == 2 ]; then

$OSEXEC gs_guc set -N all -I all -c "track_activities = on"
$OSEXEC gs_guc set -N all -I all -c "track_internal_query = off"
$OSEXEC gs_guc set -N all -I all -c "track_query_plan = on"
$OSEXEC gs_guc set -N all -I all -c "track_query_plan_size = 40960"
$OSEXEC gs_guc set -N all -I all -c "track_activity_query_size = 40960"
# $OSEXEC gs_guc set -N all -I all -c "track_internal_query_size = 40960"
# $OSEXEC gs_guc set -N all -I all -c "track_stmt_parameter = on"
$OSEXEC gs_guc set -N all -I all -c "instr_unique_sql_track_type = 'all'"
$OSEXEC gs_guc set -N all -I all -c "track_stmt_stat_level = 'L1,L1'"
$OSEXEC gs_guc set -N all -I all -c "instr_unique_sql_count = 2000000"
$OSEXEC gs_guc set -N all -I all -c "log_min_duration_statement = 100"
$OSEXEC gs_guc set -N all -I all -c "log_min_messages = warning"
fi

# 平衡
if [ $ptk_global_track_level == 1 ]; then

$OSEXEC gs_guc set -N all -I all -c "track_activities = on"
$OSEXEC gs_guc set -N all -I all -c "track_internal_query = on"
$OSEXEC gs_guc set -N all -I all -c "track_query_plan = off"
$OSEXEC gs_guc set -N all -I all -c "track_query_plan_size = 1024"
$OSEXEC gs_guc set -N all -I all -c "track_activity_query_size = 1024"
$OSEXEC gs_guc set -N all -I all -c "track_internal_query_size = 1024"
# $OSEXEC gs_guc set -N all -I all -c "track_stmt_parameter = off"
$OSEXEC gs_guc set -N all -I all -c "instr_unique_sql_track_type = 'top'"
$OSEXEC gs_guc set -N all -I all -c "track_stmt_stat_level = 'OFF,L0'"
$OSEXEC gs_guc set -N all -I all -c "instr_unique_sql_count = 10000"
$OSEXEC gs_guc set -N all -I all -c "log_min_duration_statement = 60000"
$OSEXEC gs_guc set -N all -I all -c "log_min_messages = warning"
fi

# 极致
if [ $ptk_global_track_level == 0 ]; then

$OSEXEC gs_guc set -N all -I all -c "track_activities = off"
$OSEXEC gs_guc set -N all -I all -c "track_internal_query = off"
$OSEXEC gs_guc set -N all -I all -c "track_query_plan = off"
$OSEXEC gs_guc set -N all -I all -c "track_query_plan_size = 1024"
$OSEXEC gs_guc set -N all -I all -c "track_activity_query_size = 1024"
$OSEXEC gs_guc set -N all -I all -c "track_internal_query_size = 1024"
$OSEXEC gs_guc set -N all -I all -c "track_stmt_parameter = off"
$OSEXEC gs_guc set -N all -I all -c "instr_unique_sql_track_type = 'top'"
$OSEXEC gs_guc set -N all -I all -c "track_stmt_stat_level = 'OFF,OFF'"
$OSEXEC gs_guc set -N all -I all -c "log_min_duration_statement = 10000"
$OSEXEC gs_guc set -N all -I all -c "log_min_messages = fatal"
fi

ptk cluster restart -n $ptk_global_cluster_name restart